home *** CD-ROM | disk | FTP | other *** search
/ SGI SNMP Access to HP-UX MIB 1.1.2 / SGI SNMP Access to HP-UX MIB 1.1.2.iso / dist / pcp_eoe.idb / etc / init.d / pcp.z / pcp
Text File  |  1998-04-24  |  12KB  |  486 lines

  1. #!/sbin/sh
  2. #
  3. # Start or Stop the Performance Co-Pilot Daemon(s)
  4. #
  5. # $Id: etc_init.d_pcp,v 2.65 1998/03/03 01:02:40 kenmcd Exp $
  6. #
  7.  
  8. # Some degree of paranoia here ...
  9. PATH=/usr/sbin:/usr/bsd:/sbin:/usr/bin:/bin:/usr/pcp/bin
  10. export PATH
  11.  
  12. IS_ON=/sbin/chkconfig
  13. PMCD=/usr/etc/pmcd
  14. OLDPMCD=/var/pcp/lib/pmcd
  15. PMCDOPTS=/etc/config/pmcd.options
  16. RUNDIR=${PCP_LOGDIR-/var/adm/pcplog}
  17. DKPROBE=/usr/pcp/bin/dkprobe
  18. PMLOGGER=/usr/pcp/bin/pmlogger
  19. PMCHECK=/usr/pcp/bin/cron.pmcheck
  20. prog=/etc/init.d/`basename $0`
  21. PCPLOCAL=/var/pcp/etc/local
  22.  
  23. tmp=/var/tmp/$$
  24. status=1
  25. trap "rm -f $tmp.* ; exit \$status" 0 1 2 3 15
  26.  
  27. # determine real name for localhost
  28. #
  29. LOCALHOSTNAME="localhost"
  30. [ -x /usr/bsd/hostname ] && LOCALHOSTNAME=`/usr/bsd/hostname`
  31. LOGDIR=${PCP_LOGDIR-/var/adm/pcplog}/$LOCALHOSTNAME
  32.  
  33. if $IS_ON verbose
  34. then                # For a verbose startup and shutdown
  35.     ECHO=echo
  36.     REBUILDOPT=''
  37. else                # For a quiet startup and shutdown
  38.     ECHO=:
  39.     REBUILDOPT=-s
  40. fi
  41.  
  42. id=`id | sed -e "s/(.*//" -e "s/.*=//"`
  43. if [ "$id" != 0 ]
  44. then
  45.     echo "$prog:"'
  46. Error: You must be root (uid 0) to start or stop the Performance Co-Pilot PMCD.'
  47.     exit
  48. fi
  49.  
  50. _pmcd_logfile()
  51. {
  52. default=$RUNDIR/pmcd.log
  53. nawk <$PMCDOPTS '
  54. BEGIN        { logf = "'$default'" }
  55. $1 == "-l"    { if (NF > 1) logf = $2 }
  56. END        { print logf }'
  57. }
  58.  
  59. _no_libirixpmda()
  60. {
  61.     logger -p user.alert -t PCP "pmcd: $1 missing"
  62.     echo \
  63. 'Error: Cannot find '"$1"'
  64.        PMCD will start but will not export any IRIX metrics.'
  65. }
  66.  
  67. _no_lib64_pcp()
  68. {
  69.     logger -p user.alert -t PCP "pmcd: /usr/lib64/libpcp.so.2 missing"
  70.     echo \
  71. 'Error: Cannot find /usr/lib64/libpcp.so.2 , cannot start PMCD.
  72.  
  73.        You should use inst(1)/swmgr(1) to ensure that the pcp_eoe.sw64.lib
  74.        subsystem is installed.'
  75.     exit
  76. }
  77.  
  78. _reboot_setup()
  79. {
  80.     # Set up libirixpmda link so that pmcd will find it
  81.     # Only needed for 5.3, but removed for all OSs first as previous
  82.     # releases created it
  83.     #
  84.     rm -f /var/pcp/lib/libirixpmda.so /var/pcp/lib/mips_*.libirixpmda.so
  85.  
  86.     irix_version=`/sbin/uname -r`
  87.     irix_obj=`/usr/pcp/bin/pmobjstyle`
  88.  
  89.     if [ "$irix_obj" = mips_64 -a ! -f /usr/lib64/libpcp.so.2 ]
  90.     then
  91.     _no_lib64_pcp
  92.     fi
  93.  
  94.     case $irix_version
  95.     in
  96.     5.3)    if [ ! -f /usr/lib/pcp/libirixpmda.so ]
  97.         then
  98.             _no_libirixpmda /usr/lib/pcp/libirixpmda.so
  99.             echo \
  100. '       To obtain an appropriate libirixpmda you should use inst(1)/swmgr(1)
  101.        to ensure that IRIX patch 2825 (or a successor) is installed.
  102. '
  103.         else
  104.             ln -s /usr/lib/pcp/libirixpmda.so /var/pcp/lib/mips_o32.libirixpmda.so
  105.         fi
  106.         ;;
  107.     6.2)
  108.         if [ ! -f /usr/pcp/lib/$irix_obj.libirixpmda.so ]
  109.         then
  110.             _no_libirixpmda /usr/pcp/lib/$irix_obj.libirixpmda.so
  111.             echo \
  112. '       To obtain an appropriate libirixpmda you should use inst(1)/swmgr(1)
  113.        to ensure that IRIX patch 2826 (or a successor) is installed.
  114. '
  115.         fi
  116.         ;;
  117.     6.3)
  118.         if [ ! -f /usr/pcp/lib/$irix_obj.libirixpmda.so ]
  119.         then
  120.             _no_libirixpmda /usr/pcp/lib/$irix_obj.libirixpmda.so
  121.             echo \
  122. '       To obtain an appropriate libirixpmda you should use inst(1)/swmgr(1)
  123.        to ensure that IRIX patch 2827 (or a successor) is installed.
  124. '
  125.         fi
  126.         ;;
  127.     6.4)
  128.         if [ ! -f /usr/pcp/lib/$irix_obj.libirixpmda.so ]
  129.         then
  130.             _no_libirixpmda /usr/pcp/lib/$irix_obj.libirixpmda.so
  131.             echo \
  132. '       To obtain an appropriate libirixpmda you should use inst(1)/swmgr(1)
  133.        to ensure that IRIX patch 2828 (or a successor) is installed.
  134. '
  135.         fi
  136.         ;;
  137.     6.5)
  138.         if [ ! -f /usr/pcp/lib/$irix_obj.libirixpmda.so ]
  139.         then
  140.             _no_libirixpmda /usr/pcp/lib/$irix_obj.libirixpmda.so
  141.             echo \
  142. '       To obtain an appropriate libirixpmda you should use inst(1)/swmgr(1)
  143.        to ensure that the pcp_eoe.sw.eoe subsystem from the IRIX 6.5 CD set
  144.        is installed.
  145. '
  146.         fi
  147.         ;;
  148.     esac
  149.  
  150.     # base directories and house-keeping for pmlogger instances
  151.     #
  152.     if [ ! -d /var/tmp/pmlogger ]
  153.     then
  154.     mkdir /var/tmp/pmlogger
  155.     else
  156.     rm -rf $tmp.ent $tmp.pid
  157.     here=`pwd`
  158.     cd /var/tmp/pmlogger
  159.     rm -f primary vcr
  160.     ps -ef | grep pmlogger | grep -v grep | nawk '{ print $2 }' \
  161.     | sed -e 's/[     ]*//g' | sort >$tmp.pid
  162.     ls [0-9]* 2>&1 | sed -e '/\[0-9]\*/d' \
  163.     | sed -e 's/[     ][     ]*//g' | sort >$tmp.ent
  164.     # remove entries without a pmlogger process
  165.     rm -f `comm -23 $tmp.ent $tmp.pid`
  166.     rm -f $tmp.ent $tmp.pid
  167.     cd $here
  168.     fi
  169.     chmod 1777 /var/tmp/pmlogger
  170.  
  171.     [ ! -d $LOGDIR ] && mkdir -p $LOGDIR
  172.  
  173.     # Rebuild PMNS?
  174.     #
  175.     PMNSDIR=/var/pcp/pmns
  176.     if [ -d $PMNSDIR -a -f $PMNSDIR/.NeedRebuild ]
  177.     then
  178.     if [ -x $PMNSDIR/Rebuild ] 
  179.     then
  180.         $ECHO "Performance Co-Pilot rebuilding PMNS ..."
  181.         here=`pwd`
  182.         cd $PMNSDIR
  183.         ./Rebuild -du $REBUILDOPT
  184.         [ $? -eq 0 ] && rm -f .NeedRebuild
  185.         cd $here
  186.     fi
  187.     fi
  188.  
  189.     # Update /etc/magic?
  190.     #
  191.     MAGICDIR=/var/pcp/config/magic
  192.     if [ -d $MAGICDIR -a -f $MAGICDIR/.NeedUpdate ]
  193.     then
  194.     if [ -x $MAGICDIR/update-magic ] 
  195.     then
  196.         $ECHO "Performance Co-Pilot updating /etc/magic entries ..."
  197.         here=`pwd`
  198.         cd $MAGICDIR
  199.         ./update-magic
  200.         [ $? -eq 0 ] && rm -f .NeedUpdate
  201.         cd $here
  202.     fi
  203.     fi
  204. }
  205.  
  206. _start_pmlogger()
  207. {
  208.     [ ! -d /var/tmp/pmlogger ] && mkdir /var/tmp/pmlogger
  209.     chmod 1777 /var/tmp/pmlogger
  210.  
  211.     # wait for PMCD to make with the metrics, daddyo
  212.     # ... 30 seconds should suffice
  213.     #
  214.     notfound=true
  215.     for t in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
  216.     do
  217.     if pminfo -f pmcd.numagents 2>&1 | egrep 'value [0-9]*' >/dev/null 2>&1
  218.     then
  219.         notfound=false
  220.         break
  221.     fi
  222.     sleep 2
  223.     done
  224.     if $notfound
  225.     then
  226.     echo "$prog:"'
  227. Warning: Unable to contact PMCD, suggesting that PMCD may not have started.
  228.          Check the file "'"`_pmcd_logfile`"'" for possible
  229.      errors and/or warnings.
  230.      No attempt will be made to start the Performance Co-Pilot archive
  231.          logger(s).'
  232.     return
  233.     fi
  234.  
  235.     if [ -x $PMCHECK ]
  236.     then
  237.     if fgrep -s 'getopts l: c' $PMCHECK
  238.     then
  239.         # this is the PCP 1.3 version that is not reliable ...
  240.         # better to warn and not start the primary logger than
  241.         # die mysteriously trying
  242.         echo "$prog:"'
  243. Warning: Performance Co-Pilot installation is incomplete (the script
  244.          "'$PMCHECK'" appears to be from an earlier PCP
  245.          distribution) and the PCP archive logger(s) cannot be started.
  246.          You should install the pcp.sw.base from the PCP 2.0 distribution,
  247.      else
  248.         # /sbin/chkconfig pmlogger off'
  249.         return
  250.     fi
  251.     # $PMCHECK uses /var/pcp/config/pmlogger/control
  252.     # and so can start everything that is needed
  253.     $ECHO "Performance Co-Pilot starting archive loggers ..."
  254.     if [ ! -f /var/pcp/config/pmlogger/control ]
  255.     then
  256.         echo "$prog:"'
  257. Error: PCP archive logger control file /var/pcp/config/pmlogger/control
  258.        is missing!  Cannot start any Performance Co-Pilot archive logger(s).'
  259.         return
  260.     fi
  261.     if grep '^LOCALHOSTNAME[     ]*y[     ]' /var/pcp/config/pmlogger/control >/dev/null
  262.     then
  263.         :
  264.     elif grep "^$LOCALHOSTNAME[     ]*y[     ]" /var/pcp/config/pmlogger/control >/dev/null
  265.     then
  266.         :
  267.     else
  268.         echo "$prog"'
  269. Info: Initializing default PCP archive logger control for the primary
  270.       logger in the file /var/pcp/config/pmlogger/control - see
  271.       cron.pmcheck(1) for details.
  272.       This is a once only initialization after a PCP upgrade.'
  273.         if [ -f /etc/config/pmlogger.options ]
  274.         then
  275.         options=`sed </etc/config/pmlogger.options \
  276.                 -e '/^#/d' \
  277.                 -e 's/^/ /' \
  278.                 -e 's/$/ /' \
  279.                 -e 's/ -P / /g' \
  280.                 -e 's/^ //' \
  281.                 -e 's/ $//'`
  282.         else
  283.         options=''
  284.         fi
  285.         [ -z "$options" ] && options="-c config.default"
  286.         ex - /var/pcp/config/pmlogger/control <<End-of-File
  287. g/^#LOCALHOSTNAME[     ]*y[     ]/d
  288. g/^# local primary logger/d
  289. \$a
  290.  
  291. # local primary logger
  292. # /etc/init.d/pcp added this default configuration
  293. # on `date`
  294. LOCALHOSTNAME   y   n   /var/adm/pcplog/LOCALHOSTNAME   $options
  295. .
  296. w!
  297. q
  298. End-of-File
  299.     fi
  300.  
  301.     $PMCHECK
  302.     return
  303.     else
  304.     echo "$prog:"'
  305. Warning: Performance Co-Pilot installation is incomplete (at least the
  306.          script "'$PMCHECK'" is missing) and the PCP archive
  307.          logger(s) cannot be started.
  308.          You should install the pcp.sw.base from the PCP 2.0 distribution
  309.      and consult cron.pmcheck(1), else
  310.         # /sbin/chkconfig pmlogger off'
  311.     fi
  312. }
  313.  
  314. # Use /etc/pmcd.conf to find and kill pipe/socket PMDAs created by PMCD.
  315. # (First join up continued lines in config file)
  316. #
  317. _killpmdas()
  318. {
  319.     if [ ! -f /etc/pmcd.conf ]
  320.     then
  321.         echo "$prog:"'
  322. Warning: PMCD control file "/etc/pmcd.conf" is missing, cannot identify PMDAs
  323.      to be terminated.'
  324.     return
  325.     fi
  326.     for pmda in `nawk </etc/pmcd.conf '
  327. /\\\\$/        { printf "%s ", substr($0, 0, length($0) - 1); next }
  328.         { print }' \
  329. | nawk '
  330. $1 ~ /^#/                { next }
  331. tolower($3) == "pipe" && NF > 4        { print $5; next }
  332. tolower($3) == "socket" && NF > 5    { print $6; next }' \
  333. | sort -u`
  334.     do
  335.     # Give each PMDA 2 seconds after a SIGTERM to die, then SIGKILL
  336.     killall -k 2 -TERM `basename $pmda` &
  337.     done
  338.     wait
  339. }
  340.  
  341. _shutdown()
  342. {
  343.     # Send pmcd a SIGTERM, which is noted as a pending shutdown.
  344.     # When finished the currently active request, pmcd will close any
  345.     # connections and then exit.
  346.     # Wait for pmcd to terminate, make sure any agents pmcd has
  347.     # created are dead.
  348.     #
  349.     killall -TERM pmcd
  350.     $ECHO "Waiting for PMCD to terminate ...\c"
  351.     gone=0
  352.     for i in 1 2 3 4 5 6
  353.     do
  354.     sleep 3
  355.     ps -ef | egrep "($PMCD)|($OLDPMCD)" | grep -v grep >$tmp.tmp 2>&1
  356.     if [ ! -s $tmp.tmp ]
  357.     then
  358.         gone=1
  359.         break
  360.     fi
  361.  
  362.     # If they don't go in 15 seconds, SIGKILL and sleep 1 more time
  363.     # to allow any clients reading from PMCD sockets to fail so that
  364.     # socket doesn't end up in TIME_WAIT or somesuch.
  365.     #
  366.     if [ $i = 5 ]
  367.     then
  368.         $ECHO
  369.         echo "Process ..."
  370.         cat $tmp.tmp
  371.         echo "$prog: Warning: Forcing PMCD to terminate!"
  372.         killall -KILL pmcd
  373.     else
  374.         $ECHO ".\c"
  375.     fi
  376.     done
  377.     $ECHO
  378.     _killpmdas
  379.     if [ $gone != 1 ]    # It just WON'T DIE, give up.
  380.     then
  381.     echo "Process ..."
  382.     cat $tmp.tmp
  383.     echo "$prog: Warning: PMCD won't die!"
  384.     exit
  385.     fi
  386.     pmpost "stop pmcd from /etc/init.d/pcp"
  387. }
  388.  
  389. case "$1" in
  390.   'start')
  391.     ps -ef | egrep "($PMCD)|($OLDPMCD)" | grep -v grep >$tmp.tmp 2>&1
  392.     [ -s $tmp.tmp ] && _shutdown
  393.  
  394.     # PMCD and PMDA messages should go to stderr, not the GUI notifiers
  395.     #
  396.     unset PCP_STDERR
  397.  
  398.     _reboot_setup
  399.  
  400.     if [ -d /hw/rdisk ]
  401.     then
  402.         # assume this is a system with the hardware graph support,
  403.         # so dkprobe is not required
  404.         :
  405.     else
  406.         # touch all the disks so that libirixpmda sees them
  407.         [ -x $DKPROBE ] && $DKPROBE
  408.     fi
  409.  
  410.     if [ -x $PMCD ]
  411.     then
  412.         if $IS_ON pmcd
  413.         then
  414.         if [ ! -f /etc/pmcd.conf ]
  415.         then
  416.             echo "$prog:"'
  417. Error: PMCD control file "/etc/pmcd.conf" is missing, cannot start PMCD.'
  418.             exit
  419.         fi
  420.         cd $RUNDIR
  421.  
  422.         # salvage the previous versions of any PMCD and PMDA logfiles
  423.         #
  424.         for log in pmcd `sed -e '/^#/d' -e '/\[access\]/q' -e 's/[     ].*//' </etc/pmcd.conf`
  425.         do
  426.             if [ -f $log.log ]
  427.             then
  428.             rm -f $log.log.prev
  429.             mv $log.log $log.log.prev
  430.             fi
  431.         done
  432.  
  433.         $ECHO "Performance Co-Pilot starting PMCD (logfile is `_pmcd_logfile`) ..."
  434.         OPTS=`sed -e '/^#/d' -e 's/-f//' $PMCDOPTS 2> /dev/null`
  435.  
  436.         if [ `uname -r | tr -c '.\012[0-9]' ' ' | sed -e 's/ .*//' | nawk -F. '{ print $1*100+$2 }'` -ge 605 ]
  437.         then
  438.             # IRIX6.5 or later
  439.             /sbin/suattr -C CAP_SETGID+ip -c "$PMCD `echo $OPTS`"
  440.         else
  441.             $PMCD `echo $OPTS`
  442.         fi
  443.  
  444.         pmpost "start pmcd from /etc/init.d/pcp"
  445.  
  446.         if [ -x $PMLOGGER ]
  447.         then
  448.             if $IS_ON pmlogger
  449.             then
  450.             _start_pmlogger
  451.             else
  452.             # forced removal of primary symlink
  453.             rm -f /var/tmp/pmlogger/primary
  454.             fi
  455.         fi
  456.  
  457.         # site-local customisations after PCP startup
  458.         #
  459.         [ -x $PCPLOCAL ] && $PCPLOCAL start
  460.         
  461.         else
  462.         if [ "$0" = "/etc/init.d/pcp" ]
  463.         then
  464.             echo "$prog:"'
  465. Warning: Performance Co-Pilot collector (PMCD) is disabled.  To enable:
  466.         # /sbin/chkconfig pmcd on'
  467.         fi
  468.         fi
  469.     fi
  470.     status=0
  471.         ;;
  472.  
  473.   'stop')
  474.     # site-local customisations before PCP shutdown
  475.     #
  476.     [ -x $PCPLOCAL ] && $PCPLOCAL stop
  477.     _shutdown
  478.     status=0
  479.         ;;
  480.  
  481.   *)
  482.         echo "Usage: /etc/init.d/pcp {start|stop}"
  483.         ;;
  484. esac
  485.  
  486.